<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo, NexT" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="不要停止阅读">
<meta property="og:type" content="website">
<meta property="og:title" content="linghaibin-Blog">
<meta property="og:url" content="http://yoursite.com/index.html">
<meta property="og:site_name" content="linghaibin-Blog">
<meta property="og:description" content="不要停止阅读">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="linghaibin-Blog">
<meta name="twitter:description" content="不要停止阅读">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/"/>





  <title>linghaibin-Blog</title>
  














</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left 
   page-home 
 ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">linghaibin-Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">坚持 坚持 坚持 ！！！</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-tags " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/08/19/coos-手册阅读/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="linghaibin">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="linghaibin-Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/08/19/coos-手册阅读/" itemprop="url">coos 手册阅读</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-08-20T02:07:41+08:00">
                2017-08-20
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/OS/" itemprop="url" rel="index">
                    <span itemprop="name">OS</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="coos-手册-阅读"><a href="#coos-手册-阅读" class="headerlink" title="coos 手册 阅读"></a>coos 手册 阅读</h1><ol>
<li><p>删除任务 </p>
<blockquote>
<p>CoExitTask();    //删除自己</p>
<p>CoDelTask (taskID)  //删除其他任务</p>
<blockquote>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">&gt; &gt; void  myTask0 (void* pdata)</div><div class="line">&gt; &gt; &#123;</div><div class="line">&gt; &gt; 	CoExitTask();</div><div class="line">&gt; &gt; &#125;</div><div class="line">&gt; &gt; void  myTask1 (void* pdata)</div><div class="line">&gt; &gt; &#123;</div><div class="line">&gt; &gt; 	CoDelTask(taskID);</div><div class="line">&gt; &gt; &#125;</div><div class="line">&gt; &gt;</div></pre></td></tr></table></figure>
</blockquote>
</blockquote>
</li>
<li><p>任务状态</p>
<blockquote>
<p>TASK_READY  就绪任务  创建好 但是没有运行</p>
<p>TASK_RUNNING  任务在执行 占用CPU</p>
<p>TASK_WAITING   等待状态 等待一个事件的发生</p>
<p>TASK_DORMANT  静止状态  当一个任务被删除时的状态 用户不会被激活</p>
<blockquote>
<p>任务可以在这四个状态之间被更改  </p>
<p>CoSuspendTask()  转换任务的运行状态或准备状态 和 等待状态 </p>
<p>CoAwakeTask()  切换任务从等待状态到就绪状态</p>
<p><img src="C:\Users\a6735\Documents\er.png" alt="er"></p>
</blockquote>
</blockquote>
</li>
<li><p>任务控制块</p>
<blockquote>
<p>用于描述一个任务</p>
<blockquote>
<figure class="highlight c"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div></pre></td><td class="code"><pre><div class="line">&gt; &gt; <span class="number">12</span></div><div class="line">&gt; &gt; <span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> <span class="title">TCB</span></span></div><div class="line">&gt; &gt; &#123;</div><div class="line">&gt; &gt; OS_STK *stkPtr; <span class="comment">/*!&lt; The current point of task. */</span></div><div class="line">&gt; &gt; U8 prio; <span class="comment">/*!&lt; Task priority. */</span></div><div class="line">&gt; &gt; U8 state; <span class="comment">/*!&lt; TaSk status. */</span></div><div class="line">&gt; &gt; OS_TID taskID; <span class="comment">/*!&lt; Task ID. */</span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">if</span> CFG_MUTEX_EN &gt; 0</span></div><div class="line">&gt; &gt; OS_MutexID mutexID; <span class="comment">/*!&lt; Mutex ID. */</span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">endif</span></span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">if</span> CFG_EVENT_EN &gt; 0</span></div><div class="line">&gt; &gt; OS_EventID eventID; <span class="comment">/*!&lt; Event ID. */</span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">endif</span></span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">if</span> CFG_ROBIN_EN &gt;0</span></div><div class="line">&gt; &gt; U16 timeSlice; <span class="comment">/*!&lt; Task time slice */</span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">endif</span></span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">if</span> CFG_STK_CHECKOUT_EN &gt;0</span></div><div class="line">&gt; &gt; OS_STK *<span class="built_in">stack</span>; <span class="comment">/*!&lt; The top point of task. */</span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">endif</span></span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">if</span> CFG_EVENT_EN &gt; 0</span></div><div class="line">&gt; &gt; <span class="keyword">void</span>* pmail; <span class="comment">/*!&lt; Mail to task. */</span></div><div class="line">&gt; &gt; <span class="class"><span class="keyword">struct</span> <span class="title">TCB</span> *<span class="title">waitNext</span>;</span> <span class="comment">/*!&lt; Point to next TCB in the Event waitting list.*/</span></div><div class="line">&gt; &gt; <span class="class"><span class="keyword">struct</span> <span class="title">TCB</span> *<span class="title">waitPrev</span>;</span> <span class="comment">/*!&lt; Point to prev TCB in the Event waitting list.*/</span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">endif</span></span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">if</span> CFG_TASK_SCHEDULE_EN == 0</span></div><div class="line">&gt; &gt;    FUNCPtr      taskFuc;</div><div class="line">&gt; &gt;    OS_STK     *taskStk;</div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">endif</span></span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">if</span> CFG_FLAG_EN &gt; 0</span></div><div class="line">&gt; &gt; <span class="keyword">void</span>* pnode; <span class="comment">/*!&lt; Pointer to node of event flag. */</span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">endif</span></span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">if</span> CFG_TASK_WAITTING_EN &gt;0</span></div><div class="line">&gt; &gt; U32 delayTick; <span class="comment">/*!&lt; The number of ticks which delay. */</span></div><div class="line">&gt; &gt; <span class="meta">#<span class="meta-keyword">endif</span></span></div><div class="line">&gt; &gt; <span class="class"><span class="keyword">struct</span> <span class="title">TCB</span> *<span class="title">TCBnext</span>;</span> <span class="comment">/*!&lt; The pointer to next TCB. */</span></div><div class="line">&gt; &gt; <span class="class"><span class="keyword">struct</span> <span class="title">TCB</span> *<span class="title">TCBprev</span>;</span> <span class="comment">/*!&lt; The pointer to prev TCB. */</span></div><div class="line">&gt; &gt; &#125;OSTCB,*P_OSTCB;</div><div class="line">&gt; &gt;</div></pre></td></tr></table></figure>
</blockquote>
<p>&gt;</p>
<blockquote>
<blockquote>
<p>stkPtr :指向当前任务堆栈顶部的指针。coocox库斯允许每个任务有自己的堆栈的大小。在每一个任务切换，库斯保存当前CPU通过栈的运行状态，stkptr指出这样的任务可以回到以前的状态时，CPU运行一次。由于Cortex-M3有16个32位通用寄存器描述CPU的状态，一个任务的最小堆的大小是68字节（4字节用于检测堆栈溢出）</p>
<p>prio:  您分配的任务优先级。多个任务可以在coocox库斯相同的优先级份额</p>
<p>state: 任务当前的状态</p>
<p>taskID:  系统分配的任务ID，由于多个任务可以共享相同的优先级，所以优先级不能用作唯一标识符。我们使用任务ID来区分不同的任务coocox库斯。</p>
<p>mutexID:  任务等待的互斥ID</p>
<p>eventID ：任务等待的事件ID</p>
<p>timeSlice: 任务的时间片</p>
<p>Stack: 一个指针指向栈底。它可以用来检查堆栈溢出</p>
<p>Pmail: The message pointer sent to the task.</p>
<p>waitNext: 下一个任务的事件在等待TCB</p>
<p>waitPrev: 以往的任务事件等待TCB</p>
<p>taskFuc：任务函数指针，指向活动任务</p>
<p>taskStk 指向当前任务堆栈顶部的指针，指向活动任务。</p>
<p>Pnode: 指向事件标志节点的指针</p>
<p>delayTick: 前延迟事件与任务处于延迟状态时的时间差</p>
<p>TCBnext: 下一个TCB当任务在就绪列表/延迟/互斥等待名单列表。列出的任务属于由任务状态和TCB的项目确定。如果当前任务处于就绪状态，则处于就绪列表中。如果是在等待状态，由mutexid和delaytick然后判断：如果mutexid不0xffffffff，它是在互斥等待名单；如果delaytick不0xffffffff，它是在延迟列表</p>
<p>TCBprev: 以前的TCB当任务在就绪列表/延迟/互斥等待名单列表。任务所属的列表由任务状态和相关事件标志决定。</p>
</blockquote>
</blockquote>
</blockquote>
</li>
<li><p>临界状态  -中断？</p>
<blockquote>
<p>不同于其他的内核，coocox库斯不关中断处理的关键代码段，但锁调度。因此，库斯有更短的时延中断与别人比较。由于启用中断的时间与系统对实时事件的响应有关，所以它是实时内核开发人员提供的最重要的因素之一。与其他方法相比，通过锁定调度器，可以最大程度地提高系统的实时性。因为coocox库斯管理关键部分禁止任务调度，用户的应用程序不能调用API函数将挂起当前正在执行的任务的关键部分</p>
<p>CoExitTask (), CoSuspendTask<br>(), CoTickDelay (), CoTimeDelay (), CoEnterMutexSection (), CoPendSem (),<br>CoPendMail (), CoPendQueueMail (), CoWaitForSingleFlag (),<br>CoWaitForMultipleFlags () </p>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line">&gt; void Task1(void* pdata)</div><div class="line">&gt; &#123;</div><div class="line">&gt;   .....................</div><div class="line">&gt;   CoSchedLock(); // Enter Critical Section</div><div class="line">&gt;   ...............                    // Critical Code</div><div class="line">&gt;   CoSchedUnlock();   // Exit Critical Section</div><div class="line">&gt;   .....................</div><div class="line">&gt; &#125;</div><div class="line">&gt;</div></pre></td></tr></table></figure>
</blockquote>
</li>
<li><p>中断</p>
<blockquote>
<p>在coocox库斯，中断分为两大类，根据是否调用系统API函数内部或不。对于ISR无关的操作系统，coocox库斯不强迫它做任何事情，你可以像没有一个操作系统。然而，对于ISR调用系统API函数里面，coocox库斯要求你调用相关的函数时，进入或退出中断</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div></pre></td><td class="code"><pre><div class="line">&gt; void  WWDG_IRQHandler(void)</div><div class="line">&gt; &#123;</div><div class="line">&gt; CoEnterISR(); // Enter the interrupt</div><div class="line">&gt; isr_SetFlag(flagID);      // API function</div><div class="line">&gt; ..................;            // Interrupt service routine</div><div class="line">&gt; CoExitISR(); // Exit the interrupt</div><div class="line">&gt; &#125;</div><div class="line">&gt;</div></pre></td></tr></table></figure>
</blockquote>
<p>&gt;</p>
<blockquote>
<p>所有的系统API，可以称为中断服务程序开始isr_，如isr_postsem（），isr_postmail（），（）和（）isr_postqueuemail isr_setflag。任何其他API在ISR调用会导致系统混乱。当调用中断服务例程中相应的API函数时，系统需要确定任务调度是否锁定。如果解锁，系统可以正常调用它。否则，系统将向服务请求列表发送相关的服务请求，然后等待调度程序的解锁来响应它。</p>
</blockquote>
</li>
<li><p>任务同步</p>
<blockquote>
<p>任务间的同步是指一个任务只能继续执行后得到另一个任务或中断服务程序发送同步信号。有信号，在coocox库斯实现进程间同步互斥和旗帜。</p>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line">&gt; ID0 = CoCreateSem(0,1,EVENT_SORT_TYPE_FIFO); // initCnt=0,maxCnt=1,FIFO</div><div class="line">&gt; ID1 = CoCreateSem(2,5,EVENT_SORT_TYPE_PRIO); // initCnt=2,maxCnt=5,PRIO</div><div class="line">&gt; void myTaskA(void* pdata)</div><div class="line">&gt; &#123;</div><div class="line">&gt;   ..........</div><div class="line">&gt;   semID = CoCreateSem(0,1,EVENT_SORT_TYPE_FIFO);</div><div class="line">&gt;   CoPendSem(semID,0);</div><div class="line">&gt;   ..........</div><div class="line">&gt; &#125;</div><div class="line">&gt; void myTaskB(void* pdata)</div><div class="line">&gt; &#123;</div><div class="line">&gt;   ......</div><div class="line">&gt;   CoPostSem(semID);</div><div class="line">&gt;   ......</div><div class="line">&gt; &#125;</div><div class="line">&gt; void myISR(void)</div><div class="line">&gt; &#123;</div><div class="line">&gt;   CoEnterISR();</div><div class="line">&gt;   ......</div><div class="line">&gt;   isr_PostSem(semID);</div><div class="line">&gt;   CoExitISR();</div><div class="line">&gt; &#125;</div><div class="line">&gt;</div></pre></td></tr></table></figure>
</blockquote>
<p>&gt;</p>
<blockquote>
<p>​</p>
</blockquote>
</li>
</ol>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  

  
  
  

  <article class="post post-type-tags " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/08/19/stm32-寄存器配置/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="linghaibin">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="linghaibin-Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/08/19/stm32-寄存器配置/" itemprop="url">stm32 寄存器配置</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-08-20T02:03:56+08:00">
                2017-08-20
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/stm32/" itemprop="url" rel="index">
                    <span itemprop="name">stm32</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="stm32f0-寄存器配置"><a href="#stm32f0-寄存器配置" class="headerlink" title="stm32f0 寄存器配置"></a>stm32f0 寄存器配置</h1><ul>
<li>外部中断捕获</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div><div class="line">143</div><div class="line">144</div><div class="line">145</div><div class="line">146</div><div class="line">147</div><div class="line">148</div><div class="line">149</div><div class="line">150</div><div class="line">151</div><div class="line">152</div><div class="line">153</div><div class="line">154</div><div class="line">155</div><div class="line">156</div><div class="line">157</div><div class="line">158</div><div class="line">159</div><div class="line">160</div><div class="line">161</div><div class="line">162</div><div class="line">163</div><div class="line">164</div><div class="line">165</div><div class="line">166</div><div class="line">167</div><div class="line">168</div><div class="line">169</div><div class="line">170</div><div class="line">171</div><div class="line">172</div><div class="line">173</div><div class="line">174</div><div class="line">175</div><div class="line">176</div><div class="line">177</div><div class="line">178</div><div class="line">179</div><div class="line">180</div><div class="line">181</div><div class="line">182</div><div class="line">183</div><div class="line">184</div><div class="line">185</div><div class="line">186</div><div class="line">187</div><div class="line">188</div><div class="line">189</div><div class="line">190</div><div class="line">191</div><div class="line">192</div><div class="line">193</div><div class="line">194</div><div class="line">195</div><div class="line">196</div><div class="line">197</div><div class="line">198</div><div class="line">199</div><div class="line">200</div><div class="line">201</div><div class="line">202</div><div class="line">203</div><div class="line">204</div><div class="line">205</div><div class="line">206</div><div class="line">207</div><div class="line">208</div><div class="line">209</div><div class="line">210</div><div class="line">211</div><div class="line">212</div><div class="line">213</div><div class="line">214</div><div class="line">215</div><div class="line">216</div><div class="line">217</div><div class="line">218</div><div class="line">219</div><div class="line">220</div><div class="line">221</div><div class="line">222</div><div class="line">223</div><div class="line">224</div><div class="line">225</div><div class="line">226</div><div class="line">227</div><div class="line">228</div><div class="line">229</div><div class="line">230</div><div class="line">231</div><div class="line">232</div><div class="line">233</div><div class="line">234</div><div class="line">235</div><div class="line">236</div><div class="line">237</div><div class="line">238</div><div class="line">239</div><div class="line">240</div><div class="line">241</div><div class="line">242</div><div class="line">243</div><div class="line">244</div><div class="line">245</div><div class="line">246</div><div class="line">247</div><div class="line">248</div><div class="line">249</div><div class="line">250</div><div class="line">251</div><div class="line">252</div><div class="line">253</div><div class="line">254</div><div class="line">255</div><div class="line">256</div><div class="line">257</div><div class="line">258</div><div class="line">259</div><div class="line">260</div><div class="line">261</div><div class="line">262</div><div class="line">263</div><div class="line">264</div><div class="line">265</div><div class="line">266</div><div class="line">267</div><div class="line">268</div><div class="line">269</div><div class="line">270</div><div class="line">271</div><div class="line">272</div><div class="line">273</div><div class="line">274</div><div class="line">275</div><div class="line">276</div><div class="line">277</div><div class="line">278</div><div class="line">279</div><div class="line">280</div><div class="line">281</div><div class="line">282</div><div class="line">283</div><div class="line">284</div><div class="line">285</div><div class="line">286</div><div class="line">287</div><div class="line">288</div><div class="line">289</div><div class="line">290</div><div class="line">291</div><div class="line">292</div><div class="line">293</div><div class="line">294</div><div class="line">295</div><div class="line">296</div><div class="line">297</div><div class="line">298</div><div class="line">299</div><div class="line">300</div><div class="line">301</div><div class="line">302</div><div class="line">303</div><div class="line">304</div><div class="line">305</div><div class="line">306</div><div class="line">307</div><div class="line">308</div><div class="line">309</div><div class="line">310</div><div class="line">311</div><div class="line">312</div><div class="line">313</div><div class="line">314</div><div class="line">315</div><div class="line">316</div><div class="line">317</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/* 引用头文件 *****************************************************************/</span></div><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"externalcount.h"</span></span></div><div class="line"><span class="comment">/* 私有数据类型 ***************************************************************/</span></div><div class="line"><span class="comment">/* 私有常数宏 *****************************************************************/</span></div><div class="line"><span class="comment">/* 私有动作宏 *****************************************************************/</span></div><div class="line"><span class="meta">#<span class="meta-keyword">define</span> ADC1_DR_Address    0x40012440</span></div><div class="line"><span class="comment">/* 私有变量 *******************************************************************/</span></div><div class="line"><span class="comment">/* 全局变量 */</span></div><div class="line"><span class="comment">/* 私有函数声明 ***************************************************************/</span></div><div class="line"><span class="comment">/* 私有函数  ******************************************************************/</span></div><div class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">ExternalcountClock</span><span class="params">(GPIO_TypeDef* port)</span></span>&#123;</div><div class="line">    <span class="keyword">if</span> (port == GPIOA)</div><div class="line">        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);</div><div class="line">    <span class="keyword">else</span> <span class="keyword">if</span>(port == GPIOB)</div><div class="line">        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);</div><div class="line">    <span class="keyword">else</span> <span class="keyword">if</span>(port == GPIOC)</div><div class="line">        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);</div><div class="line">    <span class="keyword">else</span> <span class="keyword">if</span>(port == GPIOD)</div><div class="line">        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);</div><div class="line">    <span class="keyword">else</span> <span class="keyword">if</span>(port == GPIOE)</div><div class="line">        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE);</div><div class="line">    <span class="keyword">else</span> <span class="keyword">if</span>(port == GPIOF)</div><div class="line">        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE);</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">ExternalcountAf</span><span class="params">(Stdexternalcount_pin_TypeDef P)</span> </span>&#123;</div><div class="line">    <span class="keyword">uint8_t</span> af_num = <span class="number">0</span>;</div><div class="line">    <span class="keyword">switch</span>(P.pin) &#123;</div><div class="line">        <span class="keyword">case</span> GPIO_Pin_0:</div><div class="line">            af_num = <span class="number">0</span>;</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">        <span class="keyword">case</span> GPIO_Pin_1:</div><div class="line">            af_num = <span class="number">1</span>;</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">        <span class="keyword">case</span> GPIO_Pin_2:</div><div class="line">            af_num = <span class="number">2</span>;</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">        <span class="keyword">case</span> GPIO_Pin_3:</div><div class="line">            af_num = <span class="number">3</span>;</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">        <span class="keyword">case</span> GPIO_Pin_4:</div><div class="line">            af_num = <span class="number">4</span>;</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">        <span class="keyword">case</span> GPIO_Pin_5:</div><div class="line">            af_num = <span class="number">5</span>;</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">        <span class="keyword">case</span> GPIO_Pin_6:</div><div class="line">            af_num = <span class="number">6</span>;</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">        <span class="keyword">case</span> GPIO_Pin_7:</div><div class="line">            af_num = <span class="number">7</span>;</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">        <span class="keyword">case</span> GPIO_Pin_8:</div><div class="line">            af_num = <span class="number">8</span>;</div><div class="line">        <span class="keyword">break</span>;</div><div class="line">    &#125;</div><div class="line">    <span class="keyword">if</span>(P.port == GPIOA) &#123;</div><div class="line">        GPIO_PinAFConfig(P.port,af_num,GPIO_AF_2);</div><div class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span>(P.port == GPIOB) &#123;</div><div class="line">        GPIO_PinAFConfig(P.port,af_num,GPIO_AF_1);</div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">ExternalcountInit</span><span class="params">(Stdexternalcount_n* externalcount)</span> </span>&#123;</div><div class="line">    GPIO_InitTypeDef    GPIO_InitStructure;</div><div class="line">    EXTI_InitTypeDef   EXTI_InitStructure;</div><div class="line">    NVIC_InitTypeDef   NVIC_InitStructure;</div><div class="line"><span class="comment">//    TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;</span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//    TIM_ICInitTypeDef  TIM_ICInitStructure;</span></div><div class="line"><span class="comment">//    NVIC_InitTypeDef NVIC_InitStructure;</span></div><div class="line">    </div><div class="line">    ExternalcountClock(externalcount-&gt;XC1.port);</div><div class="line">    ExternalcountClock(externalcount-&gt;XC2.port);</div><div class="line">    ExternalcountClock(externalcount-&gt;XC3.port);</div><div class="line">    ExternalcountClock(externalcount-&gt;XC4.port);</div><div class="line">    ExternalcountClock(externalcount-&gt;XC5.port);</div><div class="line">    ExternalcountClock(externalcount-&gt;XC6.port);</div><div class="line">    ExternalcountClock(externalcount-&gt;XC7.port);</div><div class="line">    ExternalcountClock(externalcount-&gt;XC8.port);</div><div class="line">    </div><div class="line"><span class="comment">//    /* TIM2 clock enable */</span></div><div class="line"><span class="comment">//    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);</span></div><div class="line"><span class="comment">//    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);</span></div><div class="line">    </div><div class="line">    <span class="comment">/* Enable SYSCFG clock */</span></div><div class="line">    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;</div><div class="line">    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;</div><div class="line">    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;</div><div class="line">    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC1.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC1.port, &amp;GPIO_InitStructure);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC2.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC2.port, &amp;GPIO_InitStructure);</div><div class="line">   </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC3.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC3.port, &amp;GPIO_InitStructure);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC4.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC4.port, &amp;GPIO_InitStructure);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC5.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC5.port, &amp;GPIO_InitStructure);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC6.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC6.port, &amp;GPIO_InitStructure);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC7.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC7.port, &amp;GPIO_InitStructure);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC8.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC8.port, &amp;GPIO_InitStructure);</div><div class="line"><span class="comment">//    //打开端口复用</span></div><div class="line"><span class="comment">//    ExternalcountAf(externalcount-&gt;XC1);</span></div><div class="line"><span class="comment">//    ExternalcountAf(externalcount-&gt;XC2);</span></div><div class="line"><span class="comment">//    ExternalcountAf(externalcount-&gt;XC3);</span></div><div class="line"><span class="comment">//    ExternalcountAf(externalcount-&gt;XC4);</span></div><div class="line"><span class="comment">//    ExternalcountAf(externalcount-&gt;XC5);</span></div><div class="line"><span class="comment">//    ExternalcountAf(externalcount-&gt;XC6);</span></div><div class="line"><span class="comment">//    ExternalcountAf(externalcount-&gt;XC7);</span></div><div class="line"><span class="comment">//    ExternalcountAf(externalcount-&gt;XC8);</span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//    TIM_TimeBaseStructure.TIM_Prescaler = 170 - 1;</span></div><div class="line"><span class="comment">//    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;</span></div><div class="line"><span class="comment">//    TIM_TimeBaseStructure.TIM_Period = 0xffffffff;</span></div><div class="line"><span class="comment">//    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;</span></div><div class="line"><span class="comment">//    TIM_TimeBaseInit(TIM2, &amp;TIM_TimeBaseStructure);</span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//    TIM_TimeBaseStructure.TIM_Prescaler = 170 - 1;</span></div><div class="line"><span class="comment">//    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;</span></div><div class="line"><span class="comment">//    TIM_TimeBaseStructure.TIM_Period = 0xffffffff;</span></div><div class="line"><span class="comment">//    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;</span></div><div class="line"><span class="comment">//    TIM_TimeBaseInit(TIM3, &amp;TIM_TimeBaseStructure);</span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//    /* Enable the TIM1 global Interrupt */</span></div><div class="line"><span class="comment">//    NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;</span></div><div class="line"><span class="comment">//    NVIC_InitStructure.NVIC_IRQChannelPriority = 0;</span></div><div class="line"><span class="comment">//    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;</span></div><div class="line"><span class="comment">//    NVIC_Init(&amp;NVIC_InitStructure);</span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//     /* Enable the TIM1 global Interrupt */</span></div><div class="line"><span class="comment">//    NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;</span></div><div class="line"><span class="comment">//    NVIC_InitStructure.NVIC_IRQChannelPriority = 0;</span></div><div class="line"><span class="comment">//    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;</span></div><div class="line"><span class="comment">//    NVIC_Init(&amp;NVIC_InitStructure);</span></div><div class="line"><span class="comment">//    /* TIM1 configuration: Input Capture mode ---------------------</span></div><div class="line"><span class="comment">//    The external signal is connected to TIM1 CH2 pin (PA.09)  </span></div><div class="line"><span class="comment">//    The Rising edge is used as active edge,</span></div><div class="line"><span class="comment">//    The TIM1 CCR2 is used to compute the frequency value </span></div><div class="line"><span class="comment">//    ------------------------------------------------------------ */</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICFilter = 0x0;</span></div><div class="line"><span class="comment">//    TIM_ICInit(TIM2, &amp;TIM_ICInitStructure);</span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_Channel = TIM_Channel_2;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICFilter = 0x0;</span></div><div class="line"><span class="comment">//    TIM_ICInit(TIM2, &amp;TIM_ICInitStructure);</span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICFilter = 0x0;</span></div><div class="line"><span class="comment">//    TIM_ICInit(TIM2, &amp;TIM_ICInitStructure);</span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICFilter = 0x0;</span></div><div class="line"><span class="comment">//    TIM_ICInit(TIM2, &amp;TIM_ICInitStructure);</span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//    /* TIM enable counter */</span></div><div class="line"><span class="comment">//    TIM_Cmd(TIM2, ENABLE);</span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//    /* Enable the CC2 Interrupt Request */</span></div><div class="line"><span class="comment">//    TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);</span></div><div class="line"><span class="comment">//    TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);</span></div><div class="line"><span class="comment">//    TIM_ITConfig(TIM2, TIM_IT_CC3, ENABLE);</span></div><div class="line"><span class="comment">//    TIM_ITConfig(TIM2, TIM_IT_CC4, ENABLE);</span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;</span></div><div class="line"><span class="comment">//    TIM_ICInitStructure.TIM_ICFilter = 0x0;</span></div><div class="line"><span class="comment">//    TIM_ICInit(TIM3, &amp;TIM_ICInitStructure);</span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//    /* TIM enable counter */</span></div><div class="line"><span class="comment">//    TIM_Cmd(TIM3, ENABLE);</span></div><div class="line"><span class="comment">//    </span></div><div class="line"><span class="comment">//    /* Enable the CC2 Interrupt Request */</span></div><div class="line"><span class="comment">//    TIM_ITConfig(TIM3, TIM_IT_CC1, ENABLE);</span></div><div class="line">    <span class="comment">/* Configure EXTI0 line */</span></div><div class="line">    EXTI_InitStructure.EXTI_Line = EXTI_Line0;</div><div class="line">    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;</div><div class="line">    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;</div><div class="line">    EXTI_InitStructure.EXTI_LineCmd = ENABLE;</div><div class="line">    EXTI_Init(&amp;EXTI_InitStructure);</div><div class="line">    </div><div class="line">    <span class="comment">/* Enable and set EXTI0 Interrupt */</span></div><div class="line">    NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;</div><div class="line">    NVIC_InitStructure.NVIC_IRQChannelPriority = <span class="number">0x00</span>;</div><div class="line">    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;</div><div class="line">    NVIC_Init(&amp;NVIC_InitStructure);</div><div class="line">    </div><div class="line">     <span class="comment">/* Connect EXTI0 Line to PA0 pin */</span></div><div class="line">    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="keyword">uint32_t</span> Rc_Pwm_In[<span class="number">8</span>];</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">ExternalcountRead</span><span class="params">(Stdexternalcount_n* externalcount,<span class="keyword">uint8_t</span> num)</span> </span>&#123;</div><div class="line">    externalcount-&gt;XC1.val = Rc_Pwm_In[<span class="number">0</span>];</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="comment">//void TIM3_IRQHandler(void) &#123;</span></div><div class="line"><span class="comment">//    static uint32_t temp3_cnt1,temp3_cnt1_2;</span></div><div class="line"><span class="comment">//    if(TIM_GetITStatus(TIM3, TIM_IT_CC1) == SET) &#123;</span></div><div class="line"><span class="comment">//        /* Clear TIM1 Capture compare interrupt pending bit */</span></div><div class="line"><span class="comment">//        TIM_ClearITPendingBit(TIM3, TIM_IT_CC1);</span></div><div class="line"><span class="comment">//</span></div><div class="line"><span class="comment">//        if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_4) == 1) &#123;</span></div><div class="line"><span class="comment">//            TIM_OC1PolarityConfig(TIM3,TIM_ICPolarity_Falling);</span></div><div class="line"><span class="comment">//            temp3_cnt1 = TIM_GetCapture1(TIM3); </span></div><div class="line"><span class="comment">//        &#125; else &#123;</span></div><div class="line"><span class="comment">//            TIM_OC1PolarityConfig(TIM3,TIM_ICPolarity_Rising);</span></div><div class="line"><span class="comment">//            temp3_cnt1_2 = TIM_GetCapture1(TIM3);</span></div><div class="line"><span class="comment">//            </span></div><div class="line"><span class="comment">//            if(temp3_cnt1_2&gt;=temp3_cnt1)</span></div><div class="line"><span class="comment">//                Rc_Pwm_In[4] = temp3_cnt1_2-temp3_cnt1;</span></div><div class="line"><span class="comment">//            else</span></div><div class="line"><span class="comment">//                Rc_Pwm_In[4] = 0xffff-temp3_cnt1+temp3_cnt1_2+1;</span></div><div class="line"><span class="comment">//        &#125;</span></div><div class="line"><span class="comment">//    &#125; </span></div><div class="line"><span class="comment">//&#125;</span></div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">//void TIM2_IRQHandler(void)</span></div><div class="line"><span class="comment">//&#123;       </span></div><div class="line"><span class="comment">//    static uint32_t temp_cnt1,temp_cnt1_2,temp_cnt2,temp_cnt2_2,temp_cnt3,temp_cnt3_2,temp_cnt4,temp_cnt4_2;</span></div><div class="line"><span class="comment">//    if(TIM_GetITStatus(TIM2, TIM_IT_CC1) == SET) &#123;</span></div><div class="line"><span class="comment">//        /* Clear TIM1 Capture compare interrupt pending bit */</span></div><div class="line"><span class="comment">//        TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);</span></div><div class="line"><span class="comment">//</span></div><div class="line"><span class="comment">//        if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0) == 1) &#123;</span></div><div class="line"><span class="comment">//            TIM_OC1PolarityConfig(TIM2,TIM_ICPolarity_Falling);</span></div><div class="line"><span class="comment">//            temp_cnt3 = TIM_GetCapture1(TIM2); </span></div><div class="line"><span class="comment">//        &#125; else &#123;</span></div><div class="line"><span class="comment">//            TIM_OC1PolarityConfig(TIM2,TIM_ICPolarity_Rising);</span></div><div class="line"><span class="comment">//            temp_cnt3_2 = TIM_GetCapture1(TIM2);</span></div><div class="line"><span class="comment">//            if(temp_cnt3_2&gt;=temp_cnt3)</span></div><div class="line"><span class="comment">//                Rc_Pwm_In[2] = temp_cnt3_2-temp_cnt3;</span></div><div class="line"><span class="comment">//            else</span></div><div class="line"><span class="comment">//                Rc_Pwm_In[2] = 0xffff-temp_cnt3+temp_cnt3_2+1;</span></div><div class="line"><span class="comment">//        &#125;</span></div><div class="line"><span class="comment">//    &#125; else if(TIM_GetITStatus(TIM2, TIM_IT_CC3) == SET) </span></div><div class="line"><span class="comment">//    &#123;</span></div><div class="line"><span class="comment">//        /* Clear TIM1 Capture compare interrupt pending bit */</span></div><div class="line"><span class="comment">//        TIM_ClearITPendingBit(TIM2, TIM_IT_CC3);</span></div><div class="line"><span class="comment">//</span></div><div class="line"><span class="comment">//        if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_2) == 1) &#123;</span></div><div class="line"><span class="comment">//            TIM_OC3PolarityConfig(TIM2,TIM_ICPolarity_Falling);</span></div><div class="line"><span class="comment">//            temp_cnt2 = TIM_GetCapture3(TIM2); </span></div><div class="line"><span class="comment">//        &#125; else &#123;</span></div><div class="line"><span class="comment">//            TIM_OC3PolarityConfig(TIM2,TIM_ICPolarity_Rising);</span></div><div class="line"><span class="comment">//            temp_cnt2_2 = TIM_GetCapture3(TIM2);</span></div><div class="line"><span class="comment">//            if(temp_cnt2_2&gt;=temp_cnt2)</span></div><div class="line"><span class="comment">//                Rc_Pwm_In[1] = temp_cnt2_2-temp_cnt2;</span></div><div class="line"><span class="comment">//            else</span></div><div class="line"><span class="comment">//                Rc_Pwm_In[1] = 0xffff-temp_cnt2+temp_cnt2_2+1;</span></div><div class="line"><span class="comment">//        &#125;</span></div><div class="line"><span class="comment">//    &#125; else if(TIM_GetITStatus(TIM2, TIM_IT_CC2) == SET) &#123;</span></div><div class="line"><span class="comment">//        /* Clear TIM1 Capture compare interrupt pending bit */</span></div><div class="line"><span class="comment">//        TIM_ClearITPendingBit(TIM2, TIM_IT_CC2);</span></div><div class="line"><span class="comment">//        </span></div><div class="line"><span class="comment">//        if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_1) == 1) &#123;</span></div><div class="line"><span class="comment">//            TIM_OC2PolarityConfig(TIM2,TIM_ICPolarity_Falling);		//CC1P=1 设置为下降沿捕获</span></div><div class="line"><span class="comment">//            temp_cnt1 = TIM_GetCapture2(TIM2); </span></div><div class="line"><span class="comment">//        &#125; else &#123;</span></div><div class="line"><span class="comment">//            TIM_OC2PolarityConfig(TIM2,TIM_ICPolarity_Rising); //CC1P=0 设置为上升沿捕获</span></div><div class="line"><span class="comment">//            temp_cnt1_2 = TIM_GetCapture2(TIM2);</span></div><div class="line"><span class="comment">//            if(temp_cnt1_2&gt;=temp_cnt1)</span></div><div class="line"><span class="comment">//                Rc_Pwm_In[0] = temp_cnt1_2-temp_cnt1;</span></div><div class="line"><span class="comment">//            else</span></div><div class="line"><span class="comment">//                Rc_Pwm_In[0] = 0xffff-temp_cnt1+temp_cnt1_2+1;</span></div><div class="line"><span class="comment">//        &#125;</span></div><div class="line"><span class="comment">//    &#125; else if(TIM_GetITStatus(TIM2, TIM_IT_CC4) == SET) &#123;</span></div><div class="line"><span class="comment">//        /* Clear TIM1 Capture compare interrupt pending bit */</span></div><div class="line"><span class="comment">//        TIM_ClearITPendingBit(TIM2, TIM_IT_CC4);</span></div><div class="line"><span class="comment">//        </span></div><div class="line"><span class="comment">//        if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_3) == 1) &#123;</span></div><div class="line"><span class="comment">//            TIM_OC4PolarityConfig(TIM2,TIM_ICPolarity_Falling);		//CC1P=1 设置为下降沿捕获</span></div><div class="line"><span class="comment">//            temp_cnt4 = TIM_GetCapture4(TIM2); </span></div><div class="line"><span class="comment">//        &#125; else &#123;</span></div><div class="line"><span class="comment">//            TIM_OC4PolarityConfig(TIM2,TIM_ICPolarity_Rising); //CC1P=0 设置为上升沿捕获</span></div><div class="line"><span class="comment">//            temp_cnt4_2 = TIM_GetCapture4(TIM2);</span></div><div class="line"><span class="comment">//            if(temp_cnt4_2&gt;=temp_cnt4)</span></div><div class="line"><span class="comment">//                Rc_Pwm_In[3] = temp_cnt4_2-temp_cnt4;</span></div><div class="line"><span class="comment">//            else</span></div><div class="line"><span class="comment">//                Rc_Pwm_In[3] = 0xffff-temp_cnt4+temp_cnt4_2+1;</span></div><div class="line"><span class="comment">//        &#125;</span></div><div class="line"><span class="comment">//    &#125;</span></div><div class="line"><span class="comment">//&#125;</span></div><div class="line"><span class="comment">/***************************************************************END OF FILE****/</span></div></pre></td></tr></table></figure>
<ul>
<li>外部中断</li>
</ul>
<figure class="highlight c"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div><div class="line">77</div><div class="line">78</div><div class="line">79</div><div class="line">80</div><div class="line">81</div><div class="line">82</div><div class="line">83</div><div class="line">84</div><div class="line">85</div><div class="line">86</div><div class="line">87</div><div class="line">88</div><div class="line">89</div><div class="line">90</div><div class="line">91</div><div class="line">92</div><div class="line">93</div><div class="line">94</div><div class="line">95</div><div class="line">96</div><div class="line">97</div><div class="line">98</div><div class="line">99</div><div class="line">100</div><div class="line">101</div><div class="line">102</div><div class="line">103</div><div class="line">104</div><div class="line">105</div><div class="line">106</div><div class="line">107</div><div class="line">108</div><div class="line">109</div><div class="line">110</div><div class="line">111</div><div class="line">112</div><div class="line">113</div><div class="line">114</div><div class="line">115</div><div class="line">116</div><div class="line">117</div><div class="line">118</div><div class="line">119</div><div class="line">120</div><div class="line">121</div><div class="line">122</div><div class="line">123</div><div class="line">124</div><div class="line">125</div><div class="line">126</div><div class="line">127</div><div class="line">128</div><div class="line">129</div><div class="line">130</div><div class="line">131</div><div class="line">132</div><div class="line">133</div><div class="line">134</div><div class="line">135</div><div class="line">136</div><div class="line">137</div><div class="line">138</div><div class="line">139</div><div class="line">140</div><div class="line">141</div><div class="line">142</div><div class="line">143</div><div class="line">144</div><div class="line">145</div><div class="line">146</div><div class="line">147</div><div class="line">148</div><div class="line">149</div><div class="line">150</div><div class="line">151</div><div class="line">152</div><div class="line">153</div><div class="line">154</div><div class="line">155</div><div class="line">156</div><div class="line">157</div><div class="line">158</div><div class="line">159</div><div class="line">160</div><div class="line">161</div><div class="line">162</div><div class="line">163</div><div class="line">164</div><div class="line">165</div><div class="line">166</div><div class="line">167</div><div class="line">168</div><div class="line">169</div><div class="line">170</div><div class="line">171</div><div class="line">172</div><div class="line">173</div><div class="line">174</div><div class="line">175</div><div class="line">176</div><div class="line">177</div><div class="line">178</div><div class="line">179</div><div class="line">180</div><div class="line">181</div><div class="line">182</div></pre></td><td class="code"><pre><div class="line"><span class="comment">/* 引用头文件 *****************************************************************/</span></div><div class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"externalcount.h"</span></span></div><div class="line"><span class="comment">/* 私有数据类型 ***************************************************************/</span></div><div class="line"><span class="comment">/* 私有常数宏 *****************************************************************/</span></div><div class="line"><span class="comment">/* 私有动作宏 *****************************************************************/</span></div><div class="line"><span class="meta">#<span class="meta-keyword">define</span> ADC1_DR_Address    0x40012440</span></div><div class="line"><span class="comment">/* 私有变量 *******************************************************************/</span></div><div class="line"><span class="comment">/* 全局变量 */</span></div><div class="line"><span class="comment">/* 私有函数声明 ***************************************************************/</span></div><div class="line"><span class="comment">/* 私有函数  ******************************************************************/</span></div><div class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">ExternalcountClock</span><span class="params">(GPIO_TypeDef* port)</span></span>&#123;</div><div class="line">    <span class="keyword">if</span> (port == GPIOA)</div><div class="line">        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);</div><div class="line">    <span class="keyword">else</span> <span class="keyword">if</span>(port == GPIOB)</div><div class="line">        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);</div><div class="line">    <span class="keyword">else</span> <span class="keyword">if</span>(port == GPIOC)</div><div class="line">        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);</div><div class="line">    <span class="keyword">else</span> <span class="keyword">if</span>(port == GPIOD)</div><div class="line">        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOD, ENABLE);</div><div class="line">    <span class="keyword">else</span> <span class="keyword">if</span>(port == GPIOE)</div><div class="line">        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE);</div><div class="line">    <span class="keyword">else</span> <span class="keyword">if</span>(port == GPIOF)</div><div class="line">        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF, ENABLE);</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">ExternalcountInit</span><span class="params">(Stdexternalcount_n* externalcount)</span> </span>&#123;</div><div class="line">    GPIO_InitTypeDef    GPIO_InitStructure;</div><div class="line">    EXTI_InitTypeDef   EXTI_InitStructure;</div><div class="line">    NVIC_InitTypeDef   NVIC_InitStructure;</div><div class="line">    </div><div class="line">    ExternalcountClock(externalcount-&gt;XC1.port);</div><div class="line">    ExternalcountClock(externalcount-&gt;XC2.port);</div><div class="line">    ExternalcountClock(externalcount-&gt;XC3.port);</div><div class="line">    ExternalcountClock(externalcount-&gt;XC4.port);</div><div class="line">    ExternalcountClock(externalcount-&gt;XC5.port);</div><div class="line">    ExternalcountClock(externalcount-&gt;XC6.port);</div><div class="line">    ExternalcountClock(externalcount-&gt;XC7.port);</div><div class="line">    ExternalcountClock(externalcount-&gt;XC8.port);</div><div class="line">    </div><div class="line">    <span class="comment">/* Enable SYSCFG clock */</span></div><div class="line">    RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;</div><div class="line">    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC1.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC1.port, &amp;GPIO_InitStructure);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC2.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC2.port, &amp;GPIO_InitStructure);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC3.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC3.port, &amp;GPIO_InitStructure);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC4.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC4.port, &amp;GPIO_InitStructure);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC5.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC5.port, &amp;GPIO_InitStructure);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC6.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC6.port, &amp;GPIO_InitStructure);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC7.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC7.port, &amp;GPIO_InitStructure);</div><div class="line">    </div><div class="line">    GPIO_InitStructure.GPIO_Pin = externalcount-&gt;XC8.pin;</div><div class="line">    GPIO_Init(externalcount-&gt;XC8.port, &amp;GPIO_InitStructure);</div><div class="line">    </div><div class="line">    <span class="comment">/* Configure EXTI0 line */</span></div><div class="line">    EXTI_InitStructure.EXTI_Line = EXTI_Line0;</div><div class="line">    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;</div><div class="line">    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;</div><div class="line">    EXTI_InitStructure.EXTI_LineCmd = ENABLE;</div><div class="line">    EXTI_Init(&amp;EXTI_InitStructure);</div><div class="line">    <span class="comment">/* Configure EXTI0 line */</span></div><div class="line">    EXTI_InitStructure.EXTI_Line = EXTI_Line1;</div><div class="line">    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;</div><div class="line">    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;</div><div class="line">    EXTI_InitStructure.EXTI_LineCmd = ENABLE;</div><div class="line">    EXTI_Init(&amp;EXTI_InitStructure);</div><div class="line">    <span class="comment">/* Configure EXTI0 line */</span></div><div class="line">    EXTI_InitStructure.EXTI_Line = EXTI_Line2;</div><div class="line">    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;</div><div class="line">    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;</div><div class="line">    EXTI_InitStructure.EXTI_LineCmd = ENABLE;</div><div class="line">    EXTI_Init(&amp;EXTI_InitStructure);</div><div class="line">    <span class="comment">/* Configure EXTI0 line */</span></div><div class="line">    EXTI_InitStructure.EXTI_Line = EXTI_Line3;</div><div class="line">    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;</div><div class="line">    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;</div><div class="line">    EXTI_InitStructure.EXTI_LineCmd = ENABLE;</div><div class="line">    EXTI_Init(&amp;EXTI_InitStructure);</div><div class="line">    <span class="comment">/* Configure EXTI0 line */</span></div><div class="line">    EXTI_InitStructure.EXTI_Line = EXTI_Line4;</div><div class="line">    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;</div><div class="line">    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;</div><div class="line">    EXTI_InitStructure.EXTI_LineCmd = ENABLE;</div><div class="line">    EXTI_Init(&amp;EXTI_InitStructure);</div><div class="line">    <span class="comment">/* Configure EXTI0 line */</span></div><div class="line">    EXTI_InitStructure.EXTI_Line = EXTI_Line6;</div><div class="line">    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;</div><div class="line">    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;</div><div class="line">    EXTI_InitStructure.EXTI_LineCmd = ENABLE;</div><div class="line">    EXTI_Init(&amp;EXTI_InitStructure);</div><div class="line">    </div><div class="line">    <span class="comment">/* Enable and set EXTI0 Interrupt */</span></div><div class="line">    NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;</div><div class="line">    NVIC_InitStructure.NVIC_IRQChannelPriority = <span class="number">0x00</span>;</div><div class="line">    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;</div><div class="line">    NVIC_Init(&amp;NVIC_InitStructure);</div><div class="line">    </div><div class="line">    <span class="comment">/* Enable and set EXTI0 Interrupt */</span></div><div class="line">    NVIC_InitStructure.NVIC_IRQChannel = EXTI2_3_IRQn;</div><div class="line">    NVIC_InitStructure.NVIC_IRQChannelPriority = <span class="number">0x00</span>;</div><div class="line">    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;</div><div class="line">    NVIC_Init(&amp;NVIC_InitStructure);</div><div class="line">    </div><div class="line">    <span class="comment">/* Enable and set EXTI0 Interrupt */</span></div><div class="line">    NVIC_InitStructure.NVIC_IRQChannel = EXTI4_15_IRQn;</div><div class="line">    NVIC_InitStructure.NVIC_IRQChannelPriority = <span class="number">0x00</span>;</div><div class="line">    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;</div><div class="line">    NVIC_Init(&amp;NVIC_InitStructure);</div><div class="line">    </div><div class="line">    <span class="comment">/* Connect EXTI0 Line to PA0 pin */</span></div><div class="line">    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);</div><div class="line">    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource1);</div><div class="line">    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource2);</div><div class="line">    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource3);</div><div class="line">    </div><div class="line">    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource0);</div><div class="line">    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource1);</div><div class="line">    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource4);</div><div class="line">    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource5);</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="keyword">uint32_t</span> Rc_Pwm_In[<span class="number">8</span>];</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">ExternalcountRead</span><span class="params">(Stdexternalcount_n* externalcount,<span class="keyword">uint8_t</span> num)</span> </span>&#123;</div><div class="line">    externalcount-&gt;XC1.val = Rc_Pwm_In[<span class="number">0</span>];</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">EXTI0_1_IRQHandler</span><span class="params">(<span class="keyword">void</span>)</span></span></div><div class="line">&#123;</div><div class="line">    <span class="keyword">if</span>(EXTI_GetITStatus(EXTI_Line0) != RESET) &#123;</div><div class="line">        </div><div class="line">        <span class="comment">/* Clear the EXTI line 0 pending bit */</span></div><div class="line">        EXTI_ClearITPendingBit(EXTI_Line0);</div><div class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span>(EXTI_GetITStatus(EXTI_Line1) != RESET) &#123;</div><div class="line">        </div><div class="line">        <span class="comment">/* Clear the EXTI line 0 pending bit */</span></div><div class="line">        EXTI_ClearITPendingBit(EXTI_Line1);</div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">EXTI2_3_IRQHandler</span><span class="params">(<span class="keyword">void</span>)</span></span></div><div class="line">&#123;</div><div class="line">    <span class="keyword">if</span>(EXTI_GetITStatus(EXTI_Line2) != RESET) &#123;</div><div class="line">        </div><div class="line">        <span class="comment">/* Clear the EXTI line 0 pending bit */</span></div><div class="line">        EXTI_ClearITPendingBit(EXTI_Line2);</div><div class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span>(EXTI_GetITStatus(EXTI_Line3) != RESET) &#123;</div><div class="line">        </div><div class="line">        <span class="comment">/* Clear the EXTI line 0 pending bit */</span></div><div class="line">        EXTI_ClearITPendingBit(EXTI_Line3);</div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">void</span> <span class="title">EXTI4_15_IRQHandler</span><span class="params">(<span class="keyword">void</span>)</span></span></div><div class="line">&#123;</div><div class="line">    <span class="keyword">if</span>(EXTI_GetITStatus(EXTI_Line4) != RESET) &#123;</div><div class="line">        </div><div class="line">        <span class="comment">/* Clear the EXTI line 0 pending bit */</span></div><div class="line">        EXTI_ClearITPendingBit(EXTI_Line4);</div><div class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span>(EXTI_GetITStatus(EXTI_Line4) != RESET) &#123;</div><div class="line">        </div><div class="line">        <span class="comment">/* Clear the EXTI line 0 pending bit */</span></div><div class="line">        EXTI_ClearITPendingBit(EXTI_Line4);</div><div class="line">    &#125;</div><div class="line">&#125;</div><div class="line"></div><div class="line"><span class="comment">/***************************************************************END OF FILE****/</span></div></pre></td></tr></table></figure>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  

  
  
  

  <article class="post post-type-tags " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/08/19/编程的核心/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="linghaibin">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="linghaibin-Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/08/19/编程的核心/" itemprop="url">编程的核心</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-08-20T00:59:02+08:00">
                2017-08-20
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/c-jishu/" itemprop="url" rel="index">
                    <span itemprop="name">c jishu</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="编程的核心是数据结构，而不是算法"><a href="#编程的核心是数据结构，而不是算法" class="headerlink" title="编程的核心是数据结构，而不是算法"></a>编程的核心是数据结构，而不是算法</h1><blockquote>
<p>数据是易变的，逻辑是稳定的</p>
</blockquote>
<h1 id="函数表驱动法"><a href="#函数表驱动法" class="headerlink" title="函数表驱动法"></a>函数表驱动法</h1><figure class="highlight c"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div></pre></td><td class="code"><pre><div class="line"><span class="number">1</span> <span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span>&#123;</span></div><div class="line"> <span class="number">2</span>     DOUBLE  aRangeLimit;</div><div class="line"> <span class="number">3</span>     CHAR    *pszGrade;</div><div class="line"> <span class="number">4</span> &#125;T_GRADE_MAP;</div><div class="line"> <span class="number">5</span> </div><div class="line"> <span class="number">6</span> T_GRADE_MAP gGradeMap[MAX_GRADE_LEVEL] = &#123;</div><div class="line"> <span class="number">7</span>     &#123;<span class="number">50.0</span>,              <span class="string">"Fail"</span>&#125;,</div><div class="line"> <span class="number">8</span>     &#123;<span class="number">60.0</span>,              <span class="string">"Pass"</span>&#125;,</div><div class="line"> <span class="number">9</span>     &#123;<span class="number">70.0</span>,              <span class="string">"Credit"</span>&#125;,</div><div class="line"><span class="number">10</span>     &#123;<span class="number">80.0</span>,              <span class="string">"Distinction"</span>&#125;,</div><div class="line"><span class="number">11</span>     &#123;<span class="number">100.0</span>,             <span class="string">"High Distinction"</span>&#125;</div><div class="line"><span class="number">12</span> &#125;;</div><div class="line"><span class="number">13</span> </div><div class="line"><span class="number">14</span> <span class="function"><span class="keyword">static</span> CHAR* <span class="title">EvaluateGrade</span><span class="params">(DOUBLE dScore)</span></span></div><div class="line">15 &#123;</div><div class="line"><span class="number">16</span>     INT8U ucLevel = <span class="number">0</span>;</div><div class="line"><span class="number">17</span>     <span class="keyword">for</span>(; ucLevel &lt; MAX_GRADE_LEVEL; ucLevel++)</div><div class="line"><span class="number">18</span>     &#123;</div><div class="line"><span class="number">19</span>         <span class="keyword">if</span>(dScore &lt; gGradeMap[ucLevel].aRangeLimit)</div><div class="line"><span class="number">20</span>             <span class="keyword">return</span> gGradeMap[ucLevel].pszGrade;</div><div class="line"><span class="number">21</span>     &#125;</div><div class="line"><span class="number">22</span>     <span class="keyword">return</span> gGradeMap[<span class="number">0</span>].pszGrade;</div><div class="line"><span class="number">23</span> &#125;</div></pre></td></tr></table></figure>
<h3 id="字符统计"><a href="#字符统计" class="headerlink" title="字符统计"></a>字符统计</h3><figure class="highlight c"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div><div class="line">52</div><div class="line">53</div><div class="line">54</div><div class="line">55</div><div class="line">56</div><div class="line">57</div><div class="line">58</div><div class="line">59</div><div class="line">60</div><div class="line">61</div><div class="line">62</div><div class="line">63</div><div class="line">64</div><div class="line">65</div><div class="line">66</div><div class="line">67</div><div class="line">68</div><div class="line">69</div><div class="line">70</div><div class="line">71</div><div class="line">72</div><div class="line">73</div><div class="line">74</div><div class="line">75</div><div class="line">76</div></pre></td><td class="code"><pre><div class="line"> <span class="number">1</span> <span class="comment">/* 日志控制类型定义 */</span></div><div class="line"> <span class="number">2</span> <span class="keyword">typedef</span> <span class="keyword">enum</span></div><div class="line"> <span class="number">3</span> &#123;</div><div class="line"> <span class="number">4</span>     LOG_NORM = <span class="number">0</span>,        <span class="comment">/* 未分类日志，可用于通用日志 */</span></div><div class="line"> <span class="number">5</span>     LOG_FRM,             <span class="comment">/* Frame，OMCI帧日志 */</span></div><div class="line"> <span class="number">6</span>     LOG_PON,             <span class="comment">/* Pon，光链路相关日志 */</span></div><div class="line"> <span class="number">7</span>     LOG_ETH,             <span class="comment">/* Ethernet，Layer2以太网日志 */</span></div><div class="line"> <span class="number">8</span>     LOG_NET,             <span class="comment">/* Internet，Layer3网络日志 */</span></div><div class="line"> <span class="number">9</span>     LOG_MULT,            <span class="comment">/* Multicast，组播日志 */</span></div><div class="line"><span class="number">10</span>     LOG_QOS,             <span class="comment">/* QOS，流量日志 */</span></div><div class="line"><span class="number">11</span>     LOG_CES,             <span class="comment">/* Ces，TDM电路仿真日志 */</span></div><div class="line"><span class="number">12</span>     LOG_VOIP,            <span class="comment">/* Voip，语音日志 */</span></div><div class="line"><span class="number">13</span>     LOG_ALM,             <span class="comment">/* Alarm，告警日志 */</span></div><div class="line"><span class="number">14</span>     LOG_PERF,            <span class="comment">/* Performance，性能统计日志 */</span></div><div class="line"><span class="number">15</span>     LOG_VER,             <span class="comment">/* Version，软件升级日志 */</span></div><div class="line"><span class="number">16</span>     LOG_XDSL,            <span class="comment">/* xDsl日志 */</span></div><div class="line"><span class="number">17</span>     LOG_DB,              <span class="comment">/* 数据库操作日志 */</span></div><div class="line"><span class="number">18</span>     <span class="comment">//新日志类型在此处扩展，共支持32种日志类型</span></div><div class="line"><span class="number">19</span>     LOG_ALL = UINT_MAX   <span class="comment">/* 所有日志类型 */</span></div><div class="line"><span class="number">20</span> &#125;E_LOG_TYPE;</div><div class="line"></div><div class="line"><span class="number">22</span> <span class="comment">/*****************************************************************************</span></div><div class="line">23  * 变量名称：gOmciLogCtrl</div><div class="line">24  * 作用描述：OMCI日志控制字，BitMap格式(比特编号从LSB至MSB依次为Bit0-&gt;BitN)。</div><div class="line">25  *           Bit0~N分别对应E_LOG_TYPE各枚举值(除LOG_ALL外)。</div><div class="line">26  *           BitX为0时关闭日志类型对应的日志功能，BitX为1时则予以打开。</div><div class="line">27  * 变量范围：该变量为四字节整型静态全局变量，即支持32种日志类型。</div><div class="line">28  * 访问说明：通过GetOmciLogCtrl/SetOmciLogCtrl/OmciLogCtrl函数访问/设置控制字。</div><div class="line">29  *****************************************************************************/</div><div class="line"><span class="number">30</span> <span class="keyword">static</span> INT32U gOmciLogCtrl = <span class="number">0</span>;</div><div class="line"><span class="number">31</span> </div><div class="line"><span class="number">32</span> <span class="comment">//日志类型字符串数组，下标为各字符串所对应的日志类型枚举值。</span></div><div class="line"><span class="number">33</span> <span class="keyword">static</span> <span class="keyword">const</span> INT8U* paLogTypeName[] = &#123;</div><div class="line"><span class="number">34</span>     <span class="string">"Norm"</span>,        <span class="string">"Frame"</span>,   <span class="string">"Pon"</span>,  <span class="string">"Ethernet"</span>,  <span class="string">"Internet"</span>,</div><div class="line"><span class="number">35</span>     <span class="string">"Multicast"</span>,   <span class="string">"Qos"</span>,     <span class="string">"Ces"</span>,  <span class="string">"Voip"</span>,      <span class="string">"Alarm"</span>,</div><div class="line"><span class="number">36</span>     <span class="string">"Performance"</span>, <span class="string">"Version"</span>, <span class="string">"Xdsl"</span>,  <span class="string">"Db"</span></div><div class="line"><span class="number">37</span> &#125;;</div><div class="line"><span class="number">38</span> <span class="keyword">static</span> <span class="keyword">const</span> INT8U  ucLogTypeNameNum = <span class="keyword">sizeof</span>(paLogTypeName) / <span class="keyword">sizeof</span>(paLogTypeName[<span class="number">0</span>]);</div><div class="line"><span class="number">39</span> </div><div class="line"><span class="number">40</span> <span class="function"><span class="keyword">static</span> VOID <span class="title">SetGlobalLogCtrl</span><span class="params">(E_LOG_TYPE eLogType, INT8U ucLogSwitch)</span></span></div><div class="line">41 &#123;</div><div class="line"><span class="number">42</span>     <span class="keyword">if</span>(LOG_ON == ucLogSwitch)</div><div class="line"><span class="number">43</span>         gOmciLogCtrl = LOG_ALL;</div><div class="line"><span class="number">44</span>     <span class="keyword">else</span></div><div class="line"><span class="number">45</span>         gOmciLogCtrl = <span class="number">0</span>;</div><div class="line"><span class="number">46</span> &#125;</div><div class="line"><span class="number">47</span> <span class="function"><span class="keyword">static</span> VOID <span class="title">SetSpecificLogCtrl</span><span class="params">(E_LOG_TYPE eLogType, INT8U ucLogSwitch)</span></span></div><div class="line">48 &#123;</div><div class="line"><span class="number">49</span>     <span class="keyword">if</span>(LOG_ON == ucLogSwitch)</div><div class="line"><span class="number">50</span>         SET_BIT(gOmciLogCtrl, eLogType);</div><div class="line"><span class="number">51</span>     <span class="keyword">else</span></div><div class="line"><span class="number">52</span>         CLR_BIT(gOmciLogCtrl, eLogType);</div><div class="line"><span class="number">53</span> &#125;</div><div class="line"><span class="number">54</span> </div><div class="line"><span class="number">55</span> <span class="function">VOID <span class="title">OmciLogCtrl</span><span class="params">(CHAR *pszLogType, INT8U ucLogSwitch)</span></span></div><div class="line">56 &#123;</div><div class="line"><span class="number">57</span>     <span class="keyword">if</span>(<span class="number">0</span> == strncasecmp(pszLogType, <span class="string">"All"</span>, LOG_TYPE_CMP_LEN))</div><div class="line"><span class="number">58</span>     &#123;</div><div class="line"><span class="number">59</span>         SetGlobalLogCtrl(LOG_ALL, ucLogSwitch);</div><div class="line"><span class="number">60</span>         <span class="keyword">return</span>;</div><div class="line"><span class="number">61</span>     &#125;</div><div class="line"><span class="number">62</span> </div><div class="line"><span class="number">63</span>     INT8U ucIdx = <span class="number">0</span>;</div><div class="line"><span class="number">64</span>     <span class="keyword">for</span>(ucIdx = <span class="number">0</span>; ucIdx &lt; ucLogTypeNameNum; ucIdx++)</div><div class="line"><span class="number">65</span>     &#123;</div><div class="line"><span class="number">66</span>         <span class="keyword">if</span>(<span class="number">0</span> == strncasecmp(pszLogType, paLogTypeName[ucIdx], LOG_TYPE_CMP_LEN))</div><div class="line"><span class="number">67</span>         &#123;</div><div class="line"><span class="number">68</span>             SetSpecificLogCtrl(ucIdx, ucLogSwitch);</div><div class="line"><span class="number">69</span>             <span class="built_in">printf</span>(<span class="string">"LogType: %s, LogSwitch: %s\n"</span>, paLogTypeName[ucIdx],</div><div class="line"><span class="number">70</span>                    (<span class="number">1</span>==ucLogSwitch)?<span class="string">"On"</span>:<span class="string">"Off"</span>);</div><div class="line"><span class="number">71</span>             <span class="keyword">return</span>;</div><div class="line"><span class="number">72</span>         &#125;</div><div class="line"><span class="number">73</span>     &#125;</div><div class="line"><span class="number">74</span> </div><div class="line"><span class="number">75</span>     OmciLogHelp();</div><div class="line"><span class="number">76</span> &#125;</div></pre></td></tr></table></figure>
<blockquote>
<p>Booch的《面向对象分析与设计》一书中，提到所有的程序设计语言大概有3个源流：结构化编程；面向对象编程；数据驱动编程.我认为数据驱动编程的本质是“参数化抽象”的思想，不同于OO的“规范化抽象”的思想</p>
<ol>
<li>数据驱动编程在网络游戏开发过程中很常用，但是少有人专门提到这个词</li>
<li>数据驱动编程有很多名字：元编程，解释器/虚拟机，LOP/微语言/DSL等。包括声明式编程、标记语言、甚至所见即所得的拖放控件，都算是数据驱动编程的一种吧</li>
<li>数据驱动编程可以帮助处理复杂性，和结构化编程、OO 均可相容。(正交的角度)</li>
<li>将变和不变的部分分离,策略和机制分离,由此联想到的还有 数据和代码的分离 微语言和解释器的分离 被生成代码和代码生成器的分离 更近一步 微内核插件式体系结构</li>
<li>元编程应该说是更加泛化的数据驱动编程 元编程不是新加入一个间接层 而是退居一步 使得当前的层变成一个间接层 元编程分为静态元编程(编译时)和动态元编程(运行时) 静态元编程本质上是一种 代码生成技术或者编译器技术 动态元编程一般通过解释器(或虚拟机) 加以实现</li>
<li>数据驱动编程当然也不应该说是”反抽象的”,但的确与”OO抽象”的思维方式是迥然不同 泾渭分明的,如TAOUP一书中所述:在Unix的模块化传统和围绕OO语言发展起来的使用模式之间,存在着紧张的对立关系”应该说数据驱动编程的思路与结构化编程和OO是正交的<br>编程和人的关系,更类似一种”跳出三界外,不在五行中”的做法.</li>
</ol>
</blockquote>
<p>​     人类心智的限制，一切的背后都有人的因素作为依据：</p>
<p>​     a 人同时关注的信息数量：7+-2 (所以要分模块)</p>
<p>​     b 人接收一组新信息的平均时间5s (所以要简单，系统总的模块数不要太多)</p>
<p>​     c 人思维的直观性(人的视觉能力和模糊思维能力)，这意味这两点：</p>
<p>​     A “直”——更善于思考自己能直接接触把玩的东西；(所以要“浅平透”、使用具象的设计，要尽量代码中只有顺直的流程)，</p>
<p>​     B “观”——更善于观图而不是推算逻辑；(所以要表驱动法，数据驱动编程，要UML，要可视化编程——当然MDA是太理想化了)</p>
<p>​     d 人不能持续集中注意力(人在一定的代码行数中产生的bug数量的比例是一定的，所以语言有具有表现力，要体现表达的经济性)</p>
<p>​     所以要机制与策略分离，要数据和代码分离(数据驱动编程)，要微语言，要DSL，要LOP……</p>
<p>​     e 人是有创造欲，有现实利益心的(只要偶可能总是不够遵从规范，或想创造规范谋利——只要成本能承受，在硬件领域就不行)</p>
<p>​     另外，开一个有意思的玩笑，Unix编程艺术艺术的英文缩写为TAOUP，我觉得可以理解为UP之TAO——向上抛出之道——将复杂的易变的逻辑作为数据或更高层代码抛给上层！</p>
<h2 id="3-2-函数指针"><a href="#3-2-函数指针" class="headerlink" title="3.2 函数指针"></a>3.2 函数指针</h2><p>​     “消息处理”一节示例中的函数指针有点插件结构的味道。可对这些插件进行方便替换，新增，删除，从而改变程序的行为。而这种改变，对事件处理函数的查找又是隔离的(隔离变化)。</p>
<p>​     函数指针非常有用，但使用时需注意其缺陷：无法检查参数(parameter)和返回值(return value)的类型。因为函数已经退化成指针，而指针不携带这些类型信息。缺少类型检查，当参数或返回值不一致时，可能会造成严重的错误。</p>
<p>​     例如，定义三个函数，分别具有两个参数：</p>
<p>​     int max(int x, int y)  {  return x&gt;y?x:y;  }</p>
<p>​     int min(int x, int y)  {  return x&lt;y?x:y;  }</p>
<p>​     int add(int x, int y)  {  return x+y;  }</p>
<p>​     而处理函数却定义为：</p>
<p>​     int process(int x, int y, int (<em>f)())  {  return (</em>f)(x, y);  }</p>
<p>​     其中，第三个参数是一个没有参数且返回int型变量的函数指针。但后面却用process(a,b,max)的方式进行调用，max带有两个参数。若编译器未检查出错误，而又不小心将return (<em>f)(x,y);写成return (</em>f)(x);，那么后果可能很严重。</p>
<p>​     因此在C语言中使用函数指针时，一定要小心”类型陷阱”。</p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  

  
  
  

  <article class="post post-type-tags " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/08/12/代码大全阅读记录/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="linghaibin">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="linghaibin-Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/08/12/代码大全阅读记录/" itemprop="url">代码大全阅读记录</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-08-13T04:58:32+08:00">
                2017-08-13
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/c-jishu/" itemprop="url" rel="index">
                    <span itemprop="name">c jishu</span>
                  </a>
                </span>

                
                
              
            </span>
          

          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="代码大全阅读记录"><a href="#代码大全阅读记录" class="headerlink" title="代码大全阅读记录"></a>代码大全阅读记录</h1><ul>
<li>最小复杂度</li>
</ul>
<blockquote>
<p>避免做出  聪明的设计，难以理解 易于理解简单的设计</p>
</blockquote>
<ul>
<li>易于维护</li>
</ul>
<blockquote>
<p>提高代码质量</p>
</blockquote>
<ul>
<li>松散耦合</li>
</ul>
<blockquote>
<p>通过应用类型的合理抽象，封装 信息影藏 设计出现关联少的类</p>
</blockquote>
<ul>
<li>可扩展性</li>
</ul>
<blockquote>
<p>在增强系统的功能时 无须破坏 底层结构 改动系统的某一部分 不会影响到其他部分</p>
</blockquote>
<ul>
<li>可重用性</li>
</ul>
<blockquote>
<p>设计的系统组成部分 可以在其他系统中使用 使用代价小</p>
</blockquote>
<ul>
<li>高扇入</li>
</ul>
<blockquote>
<p>大量的类使用摸个给定的类 利用 较低层次上的工具类‘’</p>
</blockquote>
<ul>
<li>低扇出</li>
</ul>
<blockquote>
<p>类里少量 或 适中的使用 其他的类  高扇出（超过约7个）说明一个类大量的使用了其他的类 会使系统变得过于复杂 低扇出的原则都是有益的</p>
</blockquote>
<ul>
<li>可移植性</li>
</ul>
<blockquote>
<p>方便移植到其他环境中去</p>
</blockquote>
<ul>
<li>精简性</li>
</ul>
<blockquote>
<p>设计出的系统没有多余的部分 </p>
</blockquote>
<ul>
<li>层次性</li>
</ul>
<blockquote>
<p>尽量保持各个系统各个分阶层的层次性，设计出的系统应该可以在任意层次上观察而不需要进入其他层次</p>
</blockquote>
<ul>
<li>标准技术</li>
</ul>
<blockquote>
<p>依赖的外来的 古怪的东西越多 理解越是头疼 要用标准话 常用的方法 让整个系统给人一种熟悉的感觉</p>
</blockquote>
<hr>
<h3 id="系统层次"><a href="#系统层次" class="headerlink" title="系统层次"></a>系统层次</h3><ul>
<li>不同子系统之间相互通讯的规则</li>
</ul>
<blockquote>
<p>所有的子系统都能与其他子系统通讯 完全失去了把他们分开所带来的好处 应该限制所有的子系统之间的通讯来让每个子系统更有存在意义</p>
<blockquote>
<p>在没有任何规则时，热力学第二定律就会发生作用，整个系统的熵将会增加，如果不对系统间的通信石佳任何限制，那么它们之间的通信就会肆意发生</p>
<blockquote>
<p>只有当‘确需了解’–最好还有合理的理由时，才应该允许子系统之间的通信。如果你还拿不准的话,那么就应该先对子系统之间的通讯加以限制，等日后需要再开放</p>
<blockquote>
<p>为了让系统之间连接简单一动且易于维护，就尽量简化子系统之间的交互关系。最简单的交互关是让一个子系统中包含另一个子系统中的类；而最复杂的的交互关系是让一个子系统中的类继承子另一个子系统的类。</p>
<blockquote>
<p>A类 -  B类  B类 - C类  C类 - A类  —大忌</p>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<ul>
<li>常见的子系统</li>
</ul>
<blockquote>
<ul>
<li>子系统会在系统中反复出现</li>
</ul>
<blockquote>
<ul>
<li>业务规则</li>
</ul>
<blockquote>
<p>在计算机的法律 规则 政策 以及 过程  比如税率 节假日安排</p>
</blockquote>
<ul>
<li>用户界面</li>
</ul>
<blockquote>
<p>把用户界面和其他部分隔离开，以便用户界面的演化不会破坏程序的其余部分 Most situation 用户界面会使用多个附属子系统或类来处理用户界面，命令行接口，菜单操作，窗体管理，帮助系统。。</p>
</blockquote>
<ul>
<li>数据库访问</li>
</ul>
<blockquote>
<p>把对数据库访问的实时细节隐藏起来，让程序不用关系绝大部分可以不必关系的底层处理细节， 提供有价值的的抽象层，从而减少程序的复杂度， 发生错误时，无须修改程序的主要部分</p>
</blockquote>
<ul>
<li>对系统的依赖性</li>
</ul>
<blockquote>
<p>把对操作系统的依赖因素归到一个子系统里，就如同把对硬件的依赖封装起来一样。 比如开发一个window系统，不要局限于window环境，把对window相关的系统调用都隔离起来，放到一个window接口系统中</p>
</blockquote>
</blockquote>
</blockquote>
<ul>
<li>分解为类</li>
</ul>
<blockquote>
<ul>
<li>类与对象的比较</li>
</ul>
<blockquote>
<p>核心 对象与类的区分 对象是指运行期间在程序中实际存在的的具体实体，而类是指在程序源码中存在的静态事物。对象是动态的 在运行期间 所能得到的值和属性</p>
</blockquote>
</blockquote>
<ul>
<li>分解成子程序</li>
</ul>
<blockquote>
<p>把每个类细分为子程序 3层定义出类接口 4层的设计将细化出类的私用子程序</p>
<p>完成的定义出类内部的子程序，常常会有助于跟好的里i接类的接口，反过来，这又有助于对类的接口进行精伊布的修改</p>
</blockquote>
<ul>
<li>子程序内部的设计</li>
</ul>
<blockquote>
<p>为每个子程序不止详细的功能，子程序的实际工作通常是由负责该子程序的开发人员完成， 包括 伪代码 选择算法 组织子程序内部的代码块</p>
</blockquote>
<p>124 page</p>
<hr>
<h3 id="表驱动法"><a href="#表驱动法" class="headerlink" title="表驱动法"></a>表驱动法</h3><ol>
<li>表驱动使用总则</li>
<li>直接访问表</li>
<li>索引访问表</li>
<li>阶梯访问表</li>
<li>表查询的其他事例</li>
<li>用决策表代替复杂的逻辑</li>
<li>用查询表代替复杂表达式</li>
</ol>
<h4 id="表驱动发使用总则"><a href="#表驱动发使用总则" class="headerlink" title="表驱动发使用总则"></a>表驱动发使用总则</h4><ul>
<li>把字符划分成 字母 标点 数字 三类</li>
<li>使用表驱动法的两个问题</li>
</ul>
<blockquote>
<ol>
<li>怎样从表中查询条目，可以用一些数据表来直接访问表。 比如说 你希望把数据按月进行分类，那么创建一个月份表是非常好的 你可以用一个下标1到12的数组实现</li>
<li>很难用于直接查表，例如 你希望按照社会安全号码做数据分类，那么除非可以承受表里存放99999999条数据，否则不能直接用号码查表，你会用更为复杂的方法</li>
</ol>
<blockquote>
<ul>
<li>直接访问</li>
<li>索引访问</li>
<li>阶梯访问</li>
</ul>
</blockquote>
<ul>
<li>表里存放的输出结果 如果是数据就存放数据 如果是动作 表查询出来的就是动作，在这种情况下，你可以保存一个描述改动作的代码 在有些语言里 你可以保存对实现该动作的子程序的引用。无论哪种情况，表都会变得更为复杂</li>
</ul>
</blockquote>
<ul>
<li>直接访问表</li>
</ul>
<blockquote>
<p>直接访问表代替了更为复杂的逻辑控制结构，无须绕很多发扎的的圈子就可以在表里面找到你想要的信息</p>
<blockquote>
<ul>
<li>事例：一个月中的天数</li>
</ul>
<blockquote>
<ul>
<li>笨做法就是写一个大的if语句</li>
</ul>
<blockquote>
<if else="">

</if></blockquote>
<ul>
<li>实现同样功能 更简单 更容易修改的是将数据存到一张表里</li>
</ul>
<blockquote>
<p>u8 integer  = {31,31,29….};</p>
<p>days = integer[ month-1 ]</p>
</blockquote>
</blockquote>
<ul>
<li>灵活的消息格式</li>
</ul>
<blockquote>
<p>打印一分存储在文件中的消息，大约500条消息，每份文件大约20种不同的消息，这些消息中会存有大约20种不同的消息。这些消息源自与一些浮标， 每条消息都有一个消息头，其中有一个ID 高速你这些消息是如何存储的</p>
</blockquote>
</blockquote>
<ul>
<li>构造查询键值</li>
</ul>
</blockquote>
<ul>
<li>索引访问表</li>
</ul>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/07/04/hello-world/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="linghaibin">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="linghaibin-Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/07/04/hello-world/" itemprop="url">Hello World</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-07-04T22:35:57+08:00">
                2017-07-04
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>Welcome to <a href="https://hexo.io/" target="_blank" rel="external">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/" target="_blank" rel="external">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html" target="_blank" rel="external">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues" target="_blank" rel="external">GitHub</a>.</p>
<h2 id="Quick-Start"><a href="#Quick-Start" class="headerlink" title="Quick Start"></a>Quick Start</h2><h3 id="Create-a-new-post"><a href="#Create-a-new-post" class="headerlink" title="Create a new post"></a>Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo new <span class="string">"My New Post"</span></div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/writing.html" target="_blank" rel="external">Writing</a></p>
<h3 id="Run-server"><a href="#Run-server" class="headerlink" title="Run server"></a>Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo server</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/server.html" target="_blank" rel="external">Server</a></p>
<h3 id="Generate-static-files"><a href="#Generate-static-files" class="headerlink" title="Generate static files"></a>Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo generate</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/generating.html" target="_blank" rel="external">Generating</a></p>
<h3 id="Deploy-to-remote-sites"><a href="#Deploy-to-remote-sites" class="headerlink" title="Deploy to remote sites"></a>Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">$ hexo deploy</div></pre></td></tr></table></figure>
<p>More info: <a href="https://hexo.io/docs/deployment.html" target="_blank" rel="external">Deployment</a></p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/07/03/build-blog/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="linghaibin">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="linghaibin-Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2017/07/03/build-blog/" itemprop="url">build blog</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-07-04T08:09:41+08:00">
                2017-07-04
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>#你好，欢迎来到我的个人技术博客。</p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
  </section>

  


          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel sidebar-panel-active">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="linghaibin" />
          <p class="site-author-name" itemprop="name">linghaibin</p>
           
              <p class="site-description motion-element" itemprop="description">不要停止阅读</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives/">
                <span class="site-state-item-count">6</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">3</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">2</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/dh-linghaibin" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">linghaibin</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
    <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>

  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
